#!/usr/bin/env bash
#
# This script is designed to be run inside the container
#

# provide defaults for required envvars
PG_CONFIG=${PG_CONFIG:-/etc/postgresql/main/postgresql.conf}
PG_LISTEN=${PG_LISTEN:-*}

# run idemptoent database configuration
sudo -i -u postgres psql postgres <<EOF
ALTER ROLE postgres WITH PASSWORD '{{ getv "/deis/database/adminPass" }}';
CREATE ROLE {{ getv "/deis/database/user" }} WITH LOGIN;
ALTER ROLE {{ getv "/deis/database/user" }} WITH PASSWORD '{{ getv "/deis/database/password" }}';
CREATE DATABASE {{ getv "/deis/database/name" }} WITH OWNER {{ getv "/deis/database/user" }};
EOF
